package com.itheima.homework;

import java.util.Random;
import java.util.Scanner;

/**
 * 抢红包
 */
public class HomeworkOptimize06 {
    public static void main(String[] args) {
        int[] hongBao = {100, 999, 50, 520, 1314};
        start(hongBao);
    }

    public static void start(int[] hongBao) {
        //写一个循环 循环次数为数组的长度
        while (true) {
            for (int i = 0; i < hongBao.length; i++) {
                Scanner sc = new Scanner(System.in);
                //每次循环，键盘录入，提示“用户录入任意键抽奖”
                System.out.println("用户录入任意键抽奖：");
                String in = sc.next();
                //随机从数组中产生一个索引，获取索引位置的元素，这个元素就表示抽到的红包
                Random r = new Random();
                int index = r.nextInt(hongBao.length);
                if (hongBao[index] != 0) {
                    System.out.println("恭喜你，您抽中了" + hongBao[index] + "元");
                    hongBao[index] = 0;
                    break;
                } else {
                    i--;
                }

            }
        }
    }
}
